package com.lm.itextpdf.example;

import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Table;

public class CreateTablePDFExample {
    public static void main(String[] args) throws Exception {
        String dest = "f://table_example.pdf";
        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
        Document document = new Document(pdfDoc);

        float[] columnWidths = {1, 5, 5};
        Table table = new Table(columnWidths);
        table.addCell(new Cell().add(new Paragraph("ID")));
        table.addCell(new Cell().add(new Paragraph("Name")));
        table.addCell(new Cell().add(new Paragraph("Description")));

        for (int i = 1; i <= 5; i++) {
            table.addCell(new Cell().add(new Paragraph(String.valueOf(i))));
            table.addCell(new Cell().add(new Paragraph("Name " + i)));
            table.addCell(new Cell().add(new Paragraph("Description " + i)));
        }

        document.add(table);
        document.close();

        System.out.println("PDF with table created at: " + dest);
    }
}
